<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="main.css">

<script src="SpryAssets/xpath.js" type="text/javascript"></script>
<script src="SpryAssets/SpryData.js" type="text/javascript"></script>
<script type="text/javascript" src="AIRAliases.js"></script>
<script type="text/javascript">
<!--

var stockSrc = new Array();
var url      = "http://wu.apple.com/fq/applewidgets/quote.asp?key=tHisIsApplewidgeTs&symbols";
var stockStr = "";
var stocks   = new Spry.Data.XMLDataSet(null, "INDEXSET/QUOTE",{loadInterval:30000,useCache:false});
var index    = new Spry.Data.XMLDataSet("http://wu.apple.com/fq/applewidgets/quote.asp?key=tHisIsApplewidgeTs&symbols=INDU+COMPX", "INDEXSET/QUOTE",{loadInterval:30000,useCache:false});
stocks.setColumnType("LASTTRADE","number");
stocks.setColumnType("CHANGE","number");
stocks.setColumnType("PCTCHANGE","number");
stocks.setColumnType("DAYLOW","number");
stocks.setColumnType("DAYHIGH","number");

index.setColumnType("LASTTRADE","number");
index.setColumnType("CHANGE","number");
index.setColumnType("PCTCHANGE","number");
index.setColumnType("DAYLOW","number");
index.setColumnType("DAYHIGH","number");
function checkNegValue(qVal)
{

	if(qVal.substring(0,1) == '-')
		return true;
		else
			return false;
}




function addStock(newStock)
{
	var stockCheck = false;
	
	for(i=0;i<stockSrc.length;i++)
	{
		if(stockSrc[i] == newStock.value)
		{
			stockCheck = true;
		}
	}
	
	if(!stockCheck)
	{
		parentSandboxBridge.saveSymbol(newStock.value);
	}
	
	
	doLoad();
	
	
	newStock.value = null; 
	
}

function doLoad()
{
	if (typeof(parentSandboxBridge) == 'undefined') {
		setTimeout('doLoad()', 1000);
	}
	
	var symbols = parentSandboxBridge.loadSymbols();
	
	for(i=0;i<symbols.length;i++)
	{
		// Add to the real-time array & build Spry URL
		stockSrc[stockSrc.length] = symbols[0].symbol;
		if(i==0)
			stockStr = "=" + symbols[0].symbol;
			else
				stockStr = stockStr + "+" + symbols[i].symbol;
	}
	
	var newURL = url + stockStr;
	
	stocks.setURL(newURL);
	stocks.loadData();
}

function deleteSymbol(symbol)
{
	parentSandboxBridge.deleteSymbol(symbol);
	symbols = new Array();
	stocks.setURL(null);
	stocks.loadData();
	doLoad();
}


//-->
</script>
</head>

<body onload="doLoad()">
<table width="100%">
	<tr>
    	<td align="left">
        	<form name="stockMgr" id="stockMgr" action="" method="post" onsubmit="addStock(document.getElementById('newStock')); return false;">
                <input type="text" name="newStock" id="newStock" />
                <input type="button" name="addStockBtn" id="addStockBtn" value="Add Stock To List" onclick="addStock(document.getElementById('newStock'));"/>
                <input type="button" name="rldStockBtn" id="rldStockBtn" value="Reload Quotes" onclick="stocks.loadData();"/>
            </form>
        </td>
        <td align="right">
        	<img src="logo.png" alt="Stock Watcher Logo" />
            <br/>
            <span class="byline">Delayed up to 20 minutes.</span>
        </td>
    </tr>
</table>

<!-- Google Ad Start -->
<div id="ads" align="center">
	<script type="text/javascript">
		<!--
		google_ad_client = "pub-6818980607943890";
		//AIR App Ad
		google_ad_slot = "7133990224";
		google_ad_width = 730;
		google_ad_height = 100;
		//-->
	</script>
	<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
<!-- Google Ad End -->
<!-- Spacer -->
<div><p>&nbsp;</p></div>

<h3 align="center">Your Stocks</h3>
<div spry:region="stocks">
	<div spry:state="loading" align="center"><img src="ajax-loader.gif"/></div>
    <div spry:state="failed" align="center">Error Loading Quotes.  Please Retry.</div>
<div spry:state="ready">
    	<div spry:if="{ds_RowCount} != 0">
          <table cellspacing="2" width="100%">
            <tr>
              <th spry:sort="COMPANYNAME">COMPANY NAME</th>
              <th spry:sort="EXCHANGE">EXCHANGE</th>
              <th spry:sort="SYMBOL">SYMBOL</th>
              <th spry:sort="LASTTRADE">LAST PRICE</th>
              <th spry:sort="CHANGE">CHANGE</th>
              <th spry:sort="PCTCHANGE">PCT CHANGE</th>
              <th spry:sort="DAYLOW">DAY LOW</th>
              <th spry:sort="DAYHIGH">DAY HIGH</th>
              <th spry:sort="VOLUME">VOLUME</th>
              <th>MARKET STATUS</th>
            </tr>
            <tr spry:repeat="stocks">
              <td><img src="delete.png" alt="Delete Stock" align="absmiddle" onclick="deleteSymbol('{SYMBOL}')" /> {COMPANYNAME}</td>
              <td  align="center">{EXCHANGE}</td>
              <td  align="center"><a href="http://finance.google.com/finance?q={SYMBOL}" title="Click for detailed info on {SYMBOL}" target="_blank">{SYMBOL}</a></td>
              <td align="right">${LASTTRADE}</td>
              <td align="right" class="decrease" spry:if="checkNegValue('{CHANGE}') && '{CHANGE}' != 'NaN'">${CHANGE}</td>
              <td align="right" class="increase" spry:if="!checkNegValue('{CHANGE}') && '{CHANGE}' != 'NaN'">${CHANGE}</td>
              <td spry:if="'{CHANGE}' == 'NaN'" align="center">-</td>
              <td align="right" class="increase" spry:if="!checkNegValue('{PCTCHANGE}') && '{PCTCHANGE}' != 'NaN'">{PCTCHANGE}%</td>
              <td align="right" class="decrease" spry:if="checkNegValue('{PCTCHANGE}') && '{PCTCHANGE}' != 'NaN'">{PCTCHANGE}%</td>
              <td spry:if="'{PCTCHANGE}' == 'NaN'" align="center">-</td>
              <td align="right" spry:if="'{DAYLOW}' != 'NaN'">${DAYLOW}</td>
              <td spry:if="'{DAYLOW}' == 'NaN'" align="center">-</td>
              <td align="right" spry:if="'{DAYHIGH}' != 'NaN'">${DAYHIGH}</td>
              <td spry:if="'{DAYHIGH}' == 'NaN'" align="center">-</td>
              <td align="right">{VOLUME}</td>
              <td spry:if="'{MKT_STATUS}' == '0'" align="center">Closed</td>
              <td spry:if="'{MKT_STATUS}' == '1'" align="center">Open</td>
            </tr>
          </table>
        </div>
        <div spry:if="{ds_RowCount} == 0" align="center">No Stocks Loaded</div>
    </div>
</div>
<hr/>
<h3 align="center">Indicies</h3>
<div spry:region="index">
	<div spry:state="loading" align="center"><img src="ajax-loader.gif"/></div>
    <div spry:state="failed" align="center">Error Loading Quotes.  Please Retry.</div>
<div spry:state="ready">
          <table cellspacing="2" width="100%">
            <tr>
              <th spry:sort="COMPANYNAME">INDEX</th>
              <th spry:sort="SYMBOL">SYMBOL</th>
              <th spry:sort="LASTTRADE">LAST PRICE</th>
              <th spry:sort="CHANGE">CHANGE</th>
              <th spry:sort="PCTCHANGE">PCT CHANGE</th>
              <th spry:sort="DAYLOW">DAY LOW</th>
              <th spry:sort="DAYHIGH">DAY HIGH</th>
              <th>MARKET STATUS</th>
            </tr>
            <tr spry:repeat="index">
              <td>{COMPANYNAME}</td>
              <td  align="center"><a href="http://finance.google.com/finance?q={SYMBOL}" target="_blank">{SYMBOL}</a></td>
              <td align="right">{LASTTRADE}</td>
              <td align="right" class="decrease" spry:if="checkNegValue('{CHANGE}') && '{CHANGE}' != 'NaN'">{CHANGE}</td>
              <td align="right" class="increase" spry:if="!checkNegValue('{CHANGE}') && '{CHANGE}' != 'NaN'">{CHANGE}</td>
              <td spry:if="'{CHANGE}' == 'NaN'" align="center">-</td>
              <td align="right" class="increase" spry:if="!checkNegValue('{PCTCHANGE}') && '{PCTCHANGE}' != 'NaN'">{PCTCHANGE}%</td>
              <td align="right" class="decrease" spry:if="checkNegValue('{PCTCHANGE}') && '{PCTCHANGE}' != 'NaN'">{PCTCHANGE}%</td>
              <td spry:if="'{PCTCHANGE}' == 'NaN'" align="center">-</td>
              <td align="right" spry:if="'{DAYLOW}' != 'NaN'">{DAYLOW}</td>
              <td spry:if="'{DAYLOW}' == 'NaN'" align="center">-</td>
              <td align="right" spry:if="'{DAYHIGH}' != 'NaN'">{DAYHIGH}</td>
              <td spry:if="'{DAYHIGH}' == 'NaN'" align="center">-</td>
              <td spry:if="'{MKT_STATUS}' == '0'" align="center">Closed</td>
              <td spry:if="'{MKT_STATUS}' == '1'" align="center">Open</td>
            </tr>
          </table>

         </div>
</div>
<!-- Spacer -->
<div><p>&nbsp;</p></div>
<!-- Google Ad Start -->
<div id="ads" align="center">
	<script type="text/javascript">
		<!--
		google_ad_client = "pub-6818980607943890";
		//AIR App Ad
		google_ad_slot = "7133990224";
		google_ad_width = 730;
		google_ad_height = 100;
		//-->
	</script>
	<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>
<!-- Google Ad End -->
<!-- Begin Google Analytics -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
	_uacct = "UA-1095671-2";
	urchinTracker();
</script>
<!-- End Google Analytics -->
</body>
</html>
